package com.store.controller.lt;

import com.store.entity.User;
import com.store.service.lt.UserService;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.UUID;

/**
 * ClassName:WebPageUtils
 * package:
 * Desription:
 *
 * @Date:2021/1/21 19:36
 * @Author: tank_李涛
 *//*
 *FileName:  WebPageUtils
 * Author:   28633
 * Date  :   2021/1/21 19:36
 * */
@Controller
@RequestMapping(value = "/lt_web")
public class WebPageController {

    @Autowired
    UserService userService;

    //跳转到忘记密码
    @RequestMapping(value = "/lt_topwd")
    public String toPwdPage() {
        return "Reception/password";
    }

    @RequestMapping(value = "/lt_topwd2")
    public String toPwdPage2() {
        return "Reception/password_2";
    }

    @RequestMapping(value = "/lt_topwd3")
    public String toPwdPage3() {
        return "Reception/password_3";
    }

    //验证手机号码是否存在
    @RequestMapping(value = "/checkPhone")
    @ResponseBody
    private ModelAndView checkPhone(@ModelAttribute("phone") String phone,ModelAndView mv) {
        System.out.println("我进入了手机号验证！！"+phone);
        try{
            User user = userService.queryUserByPhone2(phone);
            mv.addObject("user", user);
            mv.setViewName("Reception/password_2");
        }catch (Exception e){
            System.out.println("号码存在重复！");
        }
        return mv;
    }

    //更新密码
    @RequestMapping(value = "/updatePwd")
    @ResponseBody
    private ModelAndView updatePwd(@RequestParam("username") String username, @RequestParam("password") String password,ModelAndView mv) {

        System.out.println("我进入了修改密码!!!");
        System.out.println(username + "--" + password);

        int i = userService.updatePwd(username,password);

        System.out.println("i:"+i);
        if (i>0){
            mv.setViewName("Reception/password_3");
        }else{
            mv.addObject("msg","密码修改失败请重新输入！");
            mv.setViewName("Reception/password_2");
        }

        return mv;
    }
}

